package com.longcai.piaojia.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.beans.TicketEntity;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2015/6/1.
 */
public class OrderListAdapter extends ArrayAdapter<TicketEntity> {

    private LayoutInflater layoutInflater;
    private Context context;

    public OrderListAdapter(Context context, List<TicketEntity> objects) {

        super(context, 0, objects);

        this.context = context;

        layoutInflater = ((Activity)context).getLayoutInflater();

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        TicketEntity ticketEntity = getItem(position);

        if(convertView == null){

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_order_list, null)));

            convertView.setTag(viewHolder);

        }else{

            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.item_order_list_seat_tv.setText(ticketEntity.time.substring(0, 13) + context.getString(R.string.space) + ticketEntity.time.substring(ticketEntity.time.length()-5));
        viewHolder.item_order_list_floot_tv.setText(ticketEntity.count);
        viewHolder.item_order_list_price_tv.setText(ticketEntity.singlePrice + context.getString(R.string.goods_info_money_text));

        return convertView;

    }

    private class ViewHolder{

        @BoundView(R.id.item_order_list_seat_tv) public TextView item_order_list_seat_tv;
        @BoundView(R.id.item_order_list_floot_tv) public TextView item_order_list_floot_tv;
        @BoundView(R.id.item_order_list_price_tv) public TextView item_order_list_price_tv;

    }

}
